﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Communication;
using Clipper.BLL.DetectChain;
using System.Threading;

namespace Clipper.EngineerWindow
{
    /// <summary>
    /// UserControlCmd.xaml 的交互逻辑
    /// </summary>
    public partial class UserControlCmd : UserControl
    {
        public UserControlCmd()
        {
            InitializeComponent();
        }

        #region 加注系统

        private void itemFill_Loaded(object sender, RoutedEventArgs e)
        {
            userArmSA.Init(UIHelper.GetResourceText("SA"), AddReagent1AndSample.SA);
            userArmSB.Init(UIHelper.GetResourceText("SB"), AddReagent1AndSample.SB);
            userArmR1A.Init(UIHelper.GetResourceText("R1A"), AddReagent1AndSample.R1A);
            userArmR1B.Init(UIHelper.GetResourceText("R1B"), AddReagent1AndSample.R1B);
            userArmR2A.Init(UIHelper.GetResourceText("R2A"), AddReagent2.R2A);
            userArmR2B.Init(UIHelper.GetResourceText("R2B"), AddReagent2.R2B);

            valveSA.Init(AddReagent1AndSample.SA.InOpen, AddReagent1AndSample.SA.OutOpen, AddReagent1AndSample.SA.IsolatingOpen);
            valveSB.Init(AddReagent1AndSample.SB.InOpen, AddReagent1AndSample.SB.OutOpen, AddReagent1AndSample.SB.IsolatingOpen);
            valveR1A.Init(AddReagent1AndSample.R1A.InOpen, AddReagent1AndSample.R1A.OutOpen, AddReagent1AndSample.R1A.IsolatingOpen);
            valveR1B.Init(AddReagent1AndSample.R1B.InOpen, AddReagent1AndSample.R1B.OutOpen, AddReagent1AndSample.R1B.IsolatingOpen);
            valveR2A.Init(AddReagent2.R2A.InOpen, AddReagent2.R2A.OutOpen, AddReagent2.R2A.IsolatingOpen);
            valveR2B.Init(AddReagent2.R2B.InOpen, AddReagent2.R2B.OutOpen, AddReagent2.R2B.IsolatingOpen);

           
        }
        
        #endregion

        #region 传送系统
        //滑轨命令
        private void TransportCmd_Click(object sender, RoutedEventArgs e)
        {
            string btnName = ((Button)sender).Name;
            switch (btnName)
            {
                    //滑轨A--------
                case "ResetA":
                    Transportation.TransportA.Home();
                    break;
                case "LeftA":
                    Can.SendCan(Can.SA_MoveA_ID, "1AM100"+Can.strEnd);//滑轨A定位减速度
                    Transportation.TransportA.LeftPosition();
                    break;
                case "RightA":
                    Transportation.TransportA.RightPosition();
                    break;
                case "GoA":
                    Transportation.TransportA.GoIncubation();
                    break;
                    //滑轨B---------
                case "ResetB":
                    Transportation.TransportB.Home();
                    break;
                case "LeftB":
                    Transportation.TransportB.LeftPosition();
                    break;
                case "RightB":
                    Transportation.TransportB.RightPosition();
                    break;
                case "GoB":
                    Transportation.TransportB.GoIncubation();
                    break;
                    //滑轨C----------
                case "ResetC":
                    Transportation.TransportC.Home();
                    break;
                case "LeftC":
                    Transportation.TransportC.LeftPosition();
                    break;
                case "RightC":
                    Transportation.TransportC.RightPosition();
                    break;
                case "GoC":
                    Transportation.TransportC.GoIncubation();
                    break;
                    //滑轨D
                case "ResetD":
                    Transportation.TransportD.Home();
                    break;
                case "PositionD":
                    Transportation.TransportD.WashPosition();
                    break;
                case "Wash1Down":
                        WashingTank.Wash1.WashDown();
                    break;
                case "Wash1Up":
                    WashingTank.Wash1.WashUp();
                    break;
                case "Wash1Down_1":
                    WashingTank.Wash1.WashDown_1();
                    break;
                case "Wash1Move":
                    WashingTank.Wash1.MoveLittle();
                    break;
                case "Wash1In":
                    WashingTank.Wash1.WashIn(2000);
                    break;
                case "Wash1Out":
                    WashingTank.Wash1.WashOut(4000);
                    break;
                case "GoD":
                    Transportation.TransportD.GoIncubation();
                    break;
                    //滑轨E
                case "ResetE":
                    Transportation.TransportE.Home();
                    break;
                case "PositionE":
                    Transportation.TransportE.WashPosition();
                    break;
                case "Wash2Down":
                    WashingTank.Wash2.WashDown();
                    break;
                case "Wash2Up":
                    WashingTank.Wash2.WashUp();
                    break;
                case "Wash2Down_1":
                    WashingTank.Wash2.WashDown_1();
                    break;
                case "Wash2Move":
                    WashingTank.Wash2.MoveLittle();
                    break;
                case "Wash2In":
                    WashingTank.Wash2.WashIn(2000);
                    break;
                case "Wash2Out":
                    WashingTank.Wash2.WashOut(4000);
                    break;
                case "GoE":
                    Transportation.TransportE.GoIncubation();
                    break;
                //反应条传送仓
                case "btnDeliveryReset":
                    DeliveryWarehouse.DeliveryControl.Reset();
                    break;
                case "DVIn":
                    DeliveryWarehouse.DeliveryControl.CupIn();
                    break;
                case "DVBack2000":
                    DeliveryWarehouse.DeliveryControl.Back2000();
                    break;
            }

        }
        #endregion

        #region 试剂和样本
        private void KitCmd_Click(object sender, RoutedEventArgs e)
        {
            string btnName = ((Button)sender).Name;
            switch (btnName)
            {
                case "btnKit1Reset":
                    AddReagent1AndSample.Kit1.Reset();
                    break;
                case "btnKit1P":
                    AddReagent1AndSample.Kit1.Position(txtKit1.Number);
                    break;
                case "btnKit2Reset":
                    AddReagent2.Kit2.Reset();
                    break;
                case "btnKit2P":
                    AddReagent2.Kit2.Position(txtKit2.Number);
                    break;
                case "btnSampleReset":
                    AddReagent1AndSample.Sample.Reset();
                    break;
                case "btnSampleP":
                    AddReagent1AndSample.Sample.Position();
                    break;
                case "btnChangeShelf":
                    AddReagent1AndSample.Sample.ChangeShelf();
                    break;
                case "btnSM":
                    AddReagent1AndSample.Sample.GetBarcode();
                    break;
                case "btnYZ":
                    AddReagent1AndSample.Sample.CheckTube();
                    break;
                case "btnSV":
                    if(txtSV.Text!="")
                        AddReagent1AndSample.Sample.SV(txtSV.Number);
                    break;
            }
        }
        #endregion

        #region 孵育
        private void In_Click(object sender, RoutedEventArgs e)
        {
            TransportControl _Transport = Transportation.IncubationTransport;
             string btnName = ((Button)sender).Name;
             switch (btnName)
             {
                 case "btnInReset":
                     _Transport.IncubationReset();
                     break;
                 case "btnInBedReset":
                     IncubationBox.BedControl.Reset();
                     break;
                 case "btnInRock":
                     IncubationBox.BedControl.Rock();
                     break;
                 case "btnInStopRock":
                     IncubationBox.BedControl.StopRock();
                     break;
                 case "btnInR1":
                     _Transport.R1();
                     break;
                 case "btnInR1_1":
                     _Transport.R1_1();
                     break;
                 case "btnInR2":
                     _Transport.R2();
                     break;
                 case "btnInR2_1":
                     _Transport.R2_1();
                     break;
                 case "btnInWash1":
                     _Transport.Wash(1);
                     break;
                 case "btnInWash1_1":
                     _Transport.Wash_1(1);
                     break;
                 case "btnInWash2":
                     _Transport.Wash(2);
                     break;
                 case "btnInWash2_1":
                     _Transport.Wash_1(2);
                     break;
                 case "btnInSubstrate":
                     _Transport.Substrate();
                     break;
                 case "btnInSubstrate_1":
                     _Transport.Substrate_1();
                     break;
                 case "btnInDetect":
                     _Transport.Detect();
                     break;
                 case "btnInDetect_1":
                     _Transport.Detect_1();
                     break;
                 case "btnGetStrip":
                     _Transport.GetStrip(txtGetStrip.Number);
                     break;
                 case "btnDropStrip":
                     _Transport.DropStrip(txtDropStrip.Number);
                     break;
                 case "btnHeat":
                     IncubationBox.IncubationControl.Begin();
                     break;
                 case "btnStopHeat":
                     IncubationBox.IncubationControl.Stop();
                     break;
                 case "btnSetTemp":
                     IncubationBox.IncubationControl.TemperatureSet(txtSetTemp.Number);
                     break;
                 case "btnSetKitTemp":
                     IncubationBox.IncubationControl.KitTemperatureSet(txtSetKitTemp.Number);
                     break;
                 case "btnCX":
                     IncubationBox.IncubationControl.GetTemperature();
                     break;
                 case "btnCS":
                     IncubationBox.IncubationControl.GetKitTemperature();
                     break;
             }
        }
        #endregion

        #region 加底物和检测
        private void SubDetect_Click(object sender, RoutedEventArgs e)
        {
            string btnName = ((Button)sender).Name;
            switch (btnName)
            {
                //底物
                case "btnPumpReset":
                    AddSubstrate.Pump.PumpReset();
                    break;
                case "btnPumpCharge":
                    if (txtPumpCharge.Text != "")
                        AddSubstrate.Pump.PumpCharge(txtPumpCharge.Number);
                    else
                        AddSubstrate.Pump.PumpCharge();
                    break;
                case "btnSubArmReset":
                    AddSubstrate.Arm.ArmReset();
                    break;
                case "btnArmP":
                    AddSubstrate.Arm.ArmPosition();
                    break;
                case "btnAddSubstrate":
                    if(txtAddSubstrate.Text!="")
                    AddSubstrate.Arm.ArmAddSubstrate(txtAddSubstrate.Number);
                    break;
                case "btnArmOut":
                    AddSubstrate.Arm.ArmOut();
                    break;
                //检测
                case "btnDetectReset":
                    DetectionHouse.DetectControl.Reset();
                    break;
                case "btnDetectGo":
                    DetectionHouse.DetectControl.GoIncubation();
                    break;
                case "btnDetect":
                    DetectionHouse.DetectControl.OnlyDetect();
                    break;
                case "btnThrowStrip":
                    DetectionHouse.DetectControl.ThrowStrip();
                    break;
                case "btnDetectImbibe":
                    DetectionHouse.DetectControl.Imbibe();
                    break;
                case "btnDetectPStrip":
                    DetectionHouse.DetectControl.PositionStrip();
                    break;
                case "btnDetectPCup":
                    DetectionHouse.DetectControl.PositionCup();
                    break;
                case "btnUpDetector":
                    DetectionHouse.DetectControl.UpDetector();
                    break;
            }
        }
        #endregion

      

        #region 泵与阀
        private void PumpValve_Click(object sender, RoutedEventArgs e)
        {
            string btnName = ((Button)sender).Name;
            switch (btnName)
            {
                case "MainVOpen":
                    AddReagent1AndSample.SA.MainOpen();
                    break;
                case "MainVClose":
                    AddReagent1AndSample.SA.MainClose();
                    break;
                case "PumpOpen":
                    AddReagent1AndSample.PumpControl.Open();
                    break;
                case "PumpClose":
                    AddReagent1AndSample.PumpControl.Close();
                    break;

                #region 底物
                case "SubOutOpen":
                    AddSubstrate.Arm.OutOpen(true);
                    break;
                case "SubOutClose":
                    AddSubstrate.Arm.OutOpen(false);
                    break;
                case "SubIslOpen":
                    AddSubstrate.Arm.IsloationOpen(true);
                    break;
                case "SubIslClose":
                    AddSubstrate.Arm.IsloationOpen(false);
                    break;
                #endregion

                #region 清洗
                case "W1OutOpen":
                    WashingTank.Wash1.OutOpen(true);
                    break;
                case "W1OutClose":
                    WashingTank.Wash1.OutOpen(false);
                    break;
                case "W1InOpen":
                    WashingTank.Wash1.InOpen(true);
                    break;
                case "W1InClose":
                    WashingTank.Wash1.InOpen(false);
                    break;

                case "W2OutOpen":
                    WashingTank.Wash2.OutOpen(true);
                    break;
                case "W2OutClose":
                    WashingTank.Wash2.OutOpen(false);
                    break;
                case "W2InOpen":
                    WashingTank.Wash2.InOpen(true);
                    break;
                case "W2InClose":
                    WashingTank.Wash2.InOpen(false);
                    break;
                #endregion
            }
        }
        #endregion

    }
}
